import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 回收时间贬值信息 */
export interface TimeDevaluat {
          id: number; // 贬值ID
          devaluatProportion?: number; // 贬值比例
          devalDayNum: number; // 时长(单位天)
          status: number; // 状态(0-禁用,1-启用)
          sort: number; // 排序值
          remarks: string; // 备注
          groupId: number; // 组别id
}

/** 贬值组别信息 */
export interface DevaluatGroup {
          id: number; // 组别ID
          devaluatName: string; // 贬值名称
          status: boolean; // 状态(0-禁用,1-启用)
          sort: number; // 排序值
          remarks: string; // 备注
  }

// 贬值组别 API
export const DevaluatGroupApi = {
  // 查询贬值组别分页
  getDevaluatGroupPage: async (params: any) => {
    return await request.get({ url: `/recycle/devaluat-group/page`, params })
  },

  // 查询贬值组别详情
  getDevaluatGroup: async (id: number) => {
    return await request.get({ url: `/recycle/devaluat-group/get?id=` + id })
  },

  // 新增贬值组别
  createDevaluatGroup: async (data: DevaluatGroup) => {
    return await request.post({ url: `/recycle/devaluat-group/create`, data })
  },

  // 修改贬值组别
  updateDevaluatGroup: async (data: DevaluatGroup) => {
    return await request.put({ url: `/recycle/devaluat-group/update`, data })
  },

  // 删除贬值组别
  deleteDevaluatGroup: async (id: number) => {
    return await request.delete({ url: `/recycle/devaluat-group/delete?id=` + id })
  },

  /** 批量删除贬值组别 */
  deleteDevaluatGroupList: async (ids: number[]) => {
    return await request.delete({ url: `/recycle/devaluat-group/delete-list?ids=${ids.join(',')}` })
  },

  // 导出贬值组别 Excel
  exportDevaluatGroup: async (params) => {
    return await request.download({ url: `/recycle/devaluat-group/export-excel`, params })
  },

// ==================== 子表（回收时间贬值） ====================

  // 获得回收时间贬值分页
  getTimeDevaluatPage: async (params) => {
    return await request.get({ url: `/recycle/devaluat-group/time-devaluat/page`, params })
  },
  // 新增回收时间贬值
  createTimeDevaluat: async (data: TimeDevaluat) => {
    return await request.post({ url: `/recycle/devaluat-group/time-devaluat/create`, data })
  },

  // 修改回收时间贬值
  updateTimeDevaluat: async (data: TimeDevaluat) => {
    return await request.put({ url: `/recycle/devaluat-group/time-devaluat/update`, data })
  },

  // 删除回收时间贬值
  deleteTimeDevaluat: async (id: number) => {
    return await request.delete({ url: `/recycle/devaluat-group/time-devaluat/delete?id=` + id })
  },

  /** 批量删除回收时间贬值 */
  deleteTimeDevaluatList: async (ids: number[]) => {
    return await request.delete({ url: `/recycle/devaluat-group/time-devaluat/delete-list?ids=${ids.join(',')}` })
  },

  // 获得回收时间贬值
  getTimeDevaluat: async (id: number) => {
    return await request.get({ url: `/recycle/devaluat-group/time-devaluat/get?id=` + id })
  },
}